﻿using System.Linq;
using System.Collections.ObjectModel;

namespace Renci.Data.Interop.OpenGIS.Gml.Common
{
    /// <remarks/>
    [System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
    [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public class IntegerValueListType
    {
        /// <remarks/>
        [System.Xml.Serialization.XmlTextAttribute(DataType = "integer")]
        public string Value { get; set; }

        /// <remarks/>
        public static implicit operator IntegerValueListType(Collection<int> d)
        {
            return new IntegerValueListType()
            {
                Value = string.Join(" ",
                    (from n in d select n.ToString(System.Globalization.CultureInfo.InvariantCulture)).ToArray()
                    )
            };
        }

        /// <remarks/>
        public static implicit operator Collection<int>(IntegerValueListType c)
        {
            return new Collection<int>((from s in c.Value.Split(new char[] { ' ' })
                                        select int.Parse(s, System.Globalization.CultureInfo.InvariantCulture)).ToList());
        }

        /// <summary>
        /// Converts to <see cref="IntegerValueListType"/> type.
        /// </summary>
        /// <param name="d">Value to convert.</param>
        /// <returns></returns>
        public static IntegerValueListType ToIntegerValueListType(Collection<int> d)
        {
            return (IntegerValueListType)d;
        }

        /// <summary>
        /// Converts from <see cref="IntegerValueListType"/> type.
        /// </summary>
        /// <param name="c">Value to convert.</param>
        /// <returns></returns>
        public static Collection<int> FromIntegerValueListType(IntegerValueListType c)
        {
            return (Collection<int>)c;
        }
    }
}
